package gunfire.cards;

import basemod.abstracts.CustomCard;
import com.megacrit.cardcrawl.actions.AbstractGameAction;
import com.megacrit.cardcrawl.actions.common.DamageAction;
import com.megacrit.cardcrawl.actions.common.MakeTempCardInHandAction;
import com.megacrit.cardcrawl.cards.AbstractCard;
import com.megacrit.cardcrawl.cards.DamageInfo;
import com.megacrit.cardcrawl.characters.AbstractPlayer;
import com.megacrit.cardcrawl.core.CardCrawlGame;
import com.megacrit.cardcrawl.dungeons.AbstractDungeon;
import com.megacrit.cardcrawl.helpers.CardLibrary;
import com.megacrit.cardcrawl.localization.CardStrings;
import com.megacrit.cardcrawl.monsters.AbstractMonster;
import gunfire.GunfireMod;
import gunfire.characters.Taizi;

import java.util.ArrayList;
import java.util.Iterator;

import static gunfire.GunfireMod.makeCardPath;

public class EffectiveSplit extends CustomCard {

    public static final String ID = GunfireMod.makeID(EffectiveSplit.class.getSimpleName());
    private static final CardStrings cardStrings = CardCrawlGame.languagePack.getCardStrings(ID);
    public static final String NAME = cardStrings.NAME;
    public static final String DESCRIPTION = cardStrings.DESCRIPTION;
    public static final String IMG = makeCardPath("EffectiveSplit.png");
    private static final CardRarity RARITY = CardRarity.UNCOMMON;
    private static final CardType TYPE = CardType.SKILL;
    private static final CardTarget TARGET = CardTarget.NONE;
    public static final CardColor COLOR = Taizi.Enums.COLOR_GRAY;
    private static final int COST = 0;

    public EffectiveSplit() {
        super(ID, NAME, IMG, COST, DESCRIPTION, TYPE, COLOR, RARITY, TARGET);
        this.exhaust = true;
    }

    @Override
    public void upgrade() {
        if (!this.upgraded) {
            this.upgradeName();
            this.rawDescription = cardStrings.UPGRADE_DESCRIPTION;
            this.initializeDescription();
        }
    }

    @Override
    public void use(AbstractPlayer p, AbstractMonster m) {
        ArrayList<AbstractCard> qCardList = new ArrayList<>();
        for (AbstractCard r : CardLibrary.getAllCards()) {
            if (r.color == AbstractDungeon.player.getCardColor() && r.hasTag(GunfireMod.ELEMENT_DAMAGE_CARD)) {
                qCardList.add(r);
            }
        }

        for(int i = 0; i < 2; ++i) {
            AbstractCard c = qCardList.get(AbstractDungeon.cardRandomRng.random(qCardList.size() - 1)).makeCopy();
            if (this.upgraded) {
                c.upgrade();
            }
            this.addToBot(new MakeTempCardInHandAction(c, 1, false));
        }
    }

    @Override
    public AbstractCard makeCopy() {
        return new EffectiveSplit();
    }
}
